package com.atguigu.ggkt.order.controller;


import com.atguigu.ggkt.client.sequence.SequenceFeignClient;
import com.atguigu.ggkt.model.order.OrderInfo;
import com.atguigu.ggkt.model.order.PaymentInfo;
import com.atguigu.ggkt.order.mapper.PaymentInfoMapper;
import com.atguigu.ggkt.order.service.OrderInfoService;
import com.atguigu.ggkt.result.Result;
import com.atguigu.ggkt.vo.order.OrderInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 订单表 订单表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-04-28
 */
@RestController
@RequestMapping(value="/admin/order/orderInfo")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;
    @Resource
    SequenceFeignClient sequenceFeignClient;
    @Resource
    PaymentInfoMapper paymentInfoMapper;

    @ApiOperation(value = "订单列表查询")
    @GetMapping("{page}/{limit}")
    public Result listOrder(@PathVariable Long page,
                            @PathVariable Long limit,
                            OrderInfoQueryVo orderInfoQueryVo) {
        //创建page对象
        Page<OrderInfo> pageParam = new Page<>(page,limit);
        Map<String,Object> map = orderInfoService.selectOrderInfoPage(pageParam,orderInfoQueryVo);
        return Result.ok(map);
    }

    @ApiOperation(value = "验证 sequence 接口")
    @GetMapping("seq")
    public Result seq() {
        Result sequence = sequenceFeignClient.getOne();
        return Result.ok(sequence.getData());
    }

    @ApiOperation(value = "验证 PaymentInfoMapper 接口")
    @GetMapping("paymentInfo/{id}")
    public Result paymentInfo(@PathVariable String id) {

        PaymentInfo paymentInfo = paymentInfoMapper.selectById(id);
        return Result.ok(paymentInfo);
    }
}

